$(".navigation .floatleft .nav-title").css("color", "#000000");
var loseCount = parseInt(localStorage.loseCount);
console.log("LoseCount: ", loseCount);
var money = parseFloat($(".navigation_top .sheader_img_eggs:eq(1) .sheader_red").text().replace(/,/g, ""));
console.log("Current money: ", money);
var warnFlag = 0;
var total;
if(loseCount == 0) {
	console.log("refreshed...");
	total = Math.floor(money / 7250);
	localStorage.total = total;
}
else {
	console.log("not refreshed...");
	warnFlag = 1;
	total = parseInt(localStorage.total);
}
console.log("Total: ", total);

var remain = parseInt($("#RemainTitle span:eq(2)").text());

var times = 1;

var altTimes = 1;
if(loseCount > 0) {
	if(loseCount == 1) {
		altTimes = 3;
	}
	else if(loseCount == 2) {
		altTimes = 16;
	}
	else if(loseCount == 3) {
		altTimes = 100;
	}
	else if(loseCount == 4) {
		altTimes = 600;
	}
}
times = altTimes;

//刷新赔率 
var lid = window.location.href.substr(window.location.href.lastIndexOf("=")+1, 6);
var distMask = [1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1];
function isReady() {
	return (parseInt($("#RemainTitle span:eq(2)").text()) >= 3);
}
function refreshd() {
	$.ajax({
		type:"get",
		url:"pg28mode.aspx?refresh="+lid,
		error: function() {
		},
		success: function(data, textStatus) {
			var oddsList = data.split(",");
			console.log(oddsList);
			var sumFinal = 0;
			var invertOdds = new Array(28);
			var finalDist = [];
			for(var i = 0; i <= 27; i++) {
				if(distMask[i] > 0) {
					invertOdds[i] = 1 / parseFloat(oddsList[i]);
					sumFinal = sumFinal + invertOdds[i];
				}
			}
			for(var i = 0; i <= 27; i++) {
				if (distMask[i] > 0) {
					finalDist.push(Math.round(total * times / sumFinal * invertOdds[i]));
					$("#txt" + i).val(finalDist[i]);
				}
				else 
					finalDist.push(0);
			}
			localStorage.refresh = "true";
			if(isReady())
				location.href='javascript:for(var i = 0; i <= 27; i++) {$("#txt" + i).keyup().blur();};$("#conform_btn").click();$(".btnpane a").click(); void 0';
			else
				console.log("timeout...");
			console.log(finalDist);
			setTimeout(function() {
				window.location="/play/pc28.aspx";
			}, 20000);
		}
	});
}
setTimeout(function() {
		//$(".touzhu1:eq(0)").click();
		refreshd();
	},
	(remain - 7)*1000 -500);